﻿using System;
using System.Data;
using System.Configuration;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using TA.Win.Utils.Design;
using System.Drawing.Design;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Base class for all non-value controls that have a client-side behavior.
	/// </summary>
	public abstract class BaseComplexControl : TControl, IComplexControl
	{
		//protected static Properties _clientProperties = Define(BaseControl.
		#region PUBLIC
		#region INIT
		/// <summary>
		/// Ctor.
		/// </summary>
		public BaseComplexControl()
			: base(HtmlTextWriterTag.Div)
		{
			Tag = HtmlTextWriterTag.Div;
			//_initControl = new ClientEvent(this, "Init");
		}
		#endregion
		#region PROPS
		/// <summary>
		/// Gets the name of the client side class which implements the client side behavior of this control.
		/// </summary>
		[Browsable(false)]
		public virtual string ClientClassName
		{
			get
			{
				return ComplexControlCommon.GetClientClassName(this);
			}
		}
		#endregion
		#region EVENTS
		/// <summary>
		/// Raised upon initialization on the client.
		/// </summary>
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		[Category("Events")]
		[Editor(typeof(PropertyEditor), typeof(UITypeEditor))]
		public ClientEvent InitControl { get { return this.GetEvent<ClientEvent>("Init"); } }
		#endregion
		#endregion
		#region INTERNAL
		#region VARS
		//ClientEvent _initControl;
		#endregion
		#region PROPS
		#endregion
		#region METHODS
		#region INIT
		/// <summary>
		/// Registers <see cref="Script.BaseComplexControl"/>.
		/// </summary>
		protected internal override void RegisterIncludes(IncludeCollection includes)
		{
			base.RegisterIncludes(includes);

			ComplexControlCommon.RegisterIncludes(this, includes);
		}
		#endregion
		#region RENDER
		/// <summary>
		/// Renders the control markup and initialization script.
		/// </summary>
		/// <param name="writer"></param>
		public override void RenderControl(HtmlTextWriter writer)
		{
			base.RenderControl(writer);

			ComplexControlCommon.RenderControl(this, writer);
		}
		/// <summary>
		/// Renders client-side initialization script.
		/// </summary>
		/// <param name="writer"></param>
		public virtual void RenderInitScript(HtmlTextWriter writer)
		{
			ComplexControlCommon.RenderInitScript(this, writer);
		}
		/// <summary>
		/// Renders JavaScript that initializes this control's client side object.
		/// </summary>
		/// <param name="writer"></param>
		/// <param name="varName"></param>
		public virtual void RenderInitScriptInternal(HtmlTextWriter writer, string varName)
		{
		}
		/// <summary>
		/// Renders JavaScript that loads this control's client side object.
		/// </summary>
		/// <param name="writer"></param>
		/// <param name="varName"></param>
		public virtual void RenderLoadScriptInternal(HtmlTextWriter writer, string varName)
		{
		}
		/// <summary>
		/// Add all attributes to render.
		/// </summary>
		/// <param name="writer"></param>
		protected override void AddAttributesToRender(HtmlTextWriter writer)
		{
			base.AddAttributesToRender(writer);

			this.AddEventAttributes(writer);
		}
		/// <summary>
		/// Adds attributes for all events that belong to this control.
		/// </summary>
		/// <param name="writer"></param>
		protected virtual void AddEventAttributes(HtmlTextWriter writer)
		{
			ComplexControlCommon.AddEventAttributes(this, writer);
		}
		#endregion
		#endregion
		#endregion
	}
}